package oceanwiki.controller;

import freemarker.cache.FileTemplateLoader;
import io.swagger.annotations.ApiOperation;
import oceanwiki.entity.Ebook;
import oceanwiki.mapper.EbookMapper;
import oceanwiki.req.DemoReq;
import oceanwiki.resp.CommonResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @FileName TestController
 * @Description
 * @Author Me
 * @date 2024-09-08
 **/

@RestController //必须是这个注解，否则会报错
public class TestController {
    @PostMapping("/hello")
    @ApiOperation("简单测试")
    public CommonResp hello(@Valid @RequestBody DemoReq demoReq, BindingResult result) {
        return new CommonResp(true, "查询成功", demoReq);
    }

    @PostMapping("/Sayhello")
    @ApiOperation("简单简单测试")
    public CommonResp sayHello(@Valid @RequestBody DemoReq demoReq, BindingResult result) {
        return new CommonResp(true, "查询成功", demoReq);
    }

    @Autowired
    private EbookMapper ebookMapper;
    @ApiOperation("测试获取图书数据api")
    @RequestMapping("/getEBook")
    public CommonResp getEBook() {
        CommonResp commonResp = new CommonResp();
        List<Ebook> ebooks = ebookMapper.selectList(null);
        commonResp.setSuccess(true);
        commonResp.setMessage("获取成功！");
        commonResp.setContent(ebooks);
        return commonResp;
    }
}
